package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class code46 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }
        System.out.println(permute(array));

    }


    static List<List<Integer>> res = new ArrayList<>();

    public static List<List<Integer>> permute(int[] nums) {
        if (nums.length == 0){
            return res;
        }
        backtrack(nums,new ArrayList<>());
        return res;
    }

    private static void backtrack(int[] nums, List<Integer> list) {
        if (list.size() == nums.length){
            res.add(new ArrayList<>(list));
        }
        else {
            for (int i = 0; i < nums.length; i++) {
                if (list.contains(nums[i])){
                    continue;
                }
                list.add(nums[i]);
                backtrack(nums,list);
                list.remove(list.size()-1);
            }
        }
    }
}
